﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace YuFeng.Models
{
    public class AppEnum
    {
        public enum Role
        {
            [Description("管理员")]
            Admin = 1,
        }
        public enum NewsType
        {
            /// <summary>
            /// 无
            /// </summary>
            [Description("无")]
            None = 0,
            /// <summary>
            /// 公司新闻
            /// </summary>
            [Description("公司新闻")]
            CompanyNews = 1,
            /// <summary>
            /// 行业新闻
            /// </summary>
            [Description("行业新闻")]
            InlineNews = 2,

            /// <summary>
            /// 荣誉证书
            /// </summary>
            [Description("荣誉证书")]
            HonorCertificate = 3,

            /// <summary>
            /// 专利证书
            /// </summary>
            [Description("荣誉证书")]
            PatentCertificate = 4,
            /// <summary>
            /// 公司介绍
            /// </summary>
            [Description("公司介绍")]
            Introduce = 5,
            /// <summary>
            /// 联系我们
            /// </summary>
            [Description("联系我们")]
            ContactUs = 6
        }
        public enum ProductionType
        {
            /// <summary>
            /// 无
            /// </summary>
            [Description("无")]
            None = 0,
            /// <summary>
            /// 产品中心
            /// </summary>
            [Description("产品中心")]
            ProdoctCenter = 1,
            /// <summary>
            /// 行业应用
            /// </summary>
            [Description("行业应用")]
            IndustryApplication = 2
        }
        public enum LevelTypeOne
        {
            /// <summary>
            /// 无
            /// </summary>
            [Description("无")]
            None = 0,
            /// <summary>
            /// 棉花包装用聚酯捆扎带
            /// </summary>
            [Description("棉花包装用聚酯捆扎带")]
            LevelTypeOne_1 = 1,
            /// <summary>
            /// 棉花包装用塑料套袋
            /// </summary>
            [Description("棉花包装用塑料套袋")]
            LevelTypeOne_2 = 2,
            /// <summary>
            /// 焊接机
            /// </summary>
            [Description("焊接机")]
            LevelTypeOne_3 = 3,
            /// <summary>
            /// 全自动棉花捆扎机
            /// </summary>
            [Description("全自动棉花捆扎机")]
            LevelTypeOne_4 = 4,
            /// <summary>
            /// 棉花包装用聚酯捆扎带（机用带）
            /// </summary>
            [Description("聚酯捆扎带")]
            LevelTypeOne_5 = 5,
        }

        public enum LevelTypeTwo
        {
            /// <summary>
            /// 无
            /// </summary>
            [Description("无")]
            None = 0,
            /// <summary>
            /// 棉花包装用聚酯捆扎带（手工带）
            /// </summary>
            [Description("棉花包装用聚酯捆扎带（手工带）")]
            LevelTypeTwo_1 = 1,
            /// <summary>
            /// 棉花包装用聚酯捆扎带（机用带）
            /// </summary>
            [Description("棉花包装用聚酯捆扎带（机用带）")]
            LevelTypeTwo_2 = 2,
            /// <summary>
            /// 南疆
            /// </summary>
            [Description("南疆")]
            LevelTypeTwo_3 = 3,
            /// <summary>
            /// 北疆
            /// </summary>
            [Description("北疆")]
            LevelTypeTwo_4 = 4,
            /// <summary>
            /// YF-H单焊机
            /// </summary>
            [Description("YF-H单焊机")]
            LevelTypeTwo_5 = 5,
            /// <summary>
            /// YF-B收紧焊接机
            /// </summary>
            [Description("YF-B收紧焊接机")]
            LevelTypeTwo_6 = 6,
            /// <summary>
            /// 切带
            /// </summary>
            [Description("切带")]
            LevelTypeTwo_7 = 7,
            /// <summary>
            /// 卷带
            /// </summary>
            [Description("卷带")]
            LevelTypeTwo_8 = 8,
        }

        public enum MenuType
        {
            /// <summary>
            /// 点击推事件
            /// </summary>
            click,
            /// <summary>
            /// 跳转URL
            /// </summary>
            view,
            /// <summary>
            /// 扫码推事件且弹出“消息接收中”提示框
            /// </summary>
            scancode_waitmsg,
            /// <summary>
            /// 扫码推事件
            /// </summary>
            scancode_push,
            /// <summary>
            /// 弹出系统拍照发图
            /// </summary>
            pic_sysphoto,
            /// <summary>
            /// 弹出拍照或者相册发图
            /// </summary>
            pic_photo_or_album,
            /// <summary>
            /// 弹出微信相册发图器
            /// </summary>
            pic_weixin,
            /// <summary>
            /// 弹出地理位置选择器
            /// </summary>
            location_select,

        }

        public static string GetLevelTypeOne(object v)
        {
            return GetDescription(typeof(LevelTypeOne), v);
        }
        public static string GetNewsType(object v)
        {
            return GetDescription(typeof(NewsType), v);
        }
        public static string GetName(System.Type t, object v)
        {
            try
            {
                return Enum.GetName(t, v);
            }
            catch
            {
                return "UNKNOWN";
            }
        }
        /// <summary>
        /// 返回指定枚举类型的指定值的描述
        /// </summary>
        /// <param name="t">枚举类型</param>
        /// <param name="v">枚举值</param>
        /// <returns></returns>
        public static string GetDescription(System.Type t, object v)
        {
            try
            {
                if (v == null)
                {
                    return string.Empty;
                }
                FieldInfo fi = t.GetField(GetName(t, v));
                DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                return (attributes.Length > 0) ? attributes[0].Description : GetName(t, v);
            }
            catch
            {
                return "UNKNOWN";
            }
        }
        public static string GetDescriptionByName(System.Type t, string name)
        {
            try
            {
                if (name == null)
                {
                    return string.Empty;
                }
                FieldInfo fi = t.GetField(name);
                DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                return (attributes.Length > 0) ? attributes[0].Description : name;
            }
            catch
            {
                return "UNKNOWN";
            }
        }
    }
}
